var xpz_token='EWPUnCFcOg2buhuY0LBfUGubjQ7';var xpz_domain='https://jkb.lishiketang.com';var xpz_dy='https://v.douyin.com/ePLHo8H/@@@';var __xpz_kf_color__='#1f78f0';var __xpz_message_display__='block';var __xpz_m_popup_display__='block';var __xpz_r_popup_display__='block';var __xpz_message_title__='马上留言 联系卖家';var __xpz_m_popup_title1__='微信速聊，24小时实时沟通，';var __xpz_m_popup_title2__='专享客服，一对一解答！';var __xpz_r_popup_title1__='立即询价';var __r_popup_title2__='微信速聊 微信沟通';
/**
 *
 * 浮层版 客服咨询js
 * [description]
 * @return {[type]} [description]
 */

var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.type='text/css';
link.rel = 'stylesheet';
link.href =xpz_domain+'/assets/client/css/talk.css';
head.appendChild(link);
var script = document.createElement('script');
script.type = "text/javascript";
script.src = xpz_domain+"/assets/client/js/clipboard.min.js";
head.appendChild(script);


var dianqilai ={
    visiter_id:'',
    visiter_name:'',
    avatar:'',
    product:'',
    open:function(){
        var d =document.getElementById('wolive-box');
        if(!d){
            var div =document.createElement('div');
            div.id ="dianqilai-kefu";
            div.className +='dianqilai-form';
            div.style.display += __xpz_r_popup_display__;
            div.style.background += __xpz_kf_color__;
            document.body.appendChild(div);
            var w =document.getElementById('dianqilai-kefu');
            w.innerHTML=' <i class="dianqilai-icon" onclick="dianqilai.connenct(0)"></i><p class="dianqilai-item" onclick="dianqilai.connenct(0)" >'+__xpz_r_popup_title1__+'</p>';
        }

        var dd =document.getElementById('wolive-boxx');
        if(!dd){
            var div =document.createElement('div');
            div.id ="dianqilai-zjtk";
            div.className +="dianqilai-zjtk-form";
            document.body.appendChild(div);
            var ww =document.getElementById('dianqilai-zjtk');
            if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
                ww.innerHTML='<div id="xpz_container" style="display:'+__xpz_m_popup_display__+';" data-clipboard-text="'+xpz_dy+'"><div id="xpz_dialog" style="background: '+__xpz_kf_color__+';position: relative;height: 150px;width: 230px"><div style=";margin-left:14px;color: #fff;font-size: 16px;position: absolute;line-height: 30px;top:25px;">'+__xpz_m_popup_title1__+'<br>'+__xpz_m_popup_title2__+'</div><a style="font-size:15px;position: absolute;left:26px;bottom:20px;text-align:center;border-radius: 5px;width: 73px;height: 28px;line-height: 28px; display: inline-block;text-decoration: none; color: '+__xpz_kf_color__+';background:rgba(255,255,255,0.5)" href="javascript:;" onclick="dianqilai.later()">稍后再说</a><a style="font-size:15px;background-color:#f2f2f2;position: absolute;bottom:20px;right: 31px;text-align:center;border-radius: 5px;width: 73px;height: 28px;line-height: 28px; display: inline-block;text-decoration: none; color: '+__xpz_kf_color__+';" href="javascript:;" onclick="dianqilai.connenct(0)">微信速聊</a></div></div>';

            } else {
                ww.innerHTML='<div id="middle_contact" style="display:'+__xpz_m_popup_display__+';z-index:9999;position: fixed;top: 50%;left: 50%;margin-left: -225px;margin-top: -75px;width:450px;height:180px;font-size:16px;border-radius:10px;background: '+__xpz_kf_color__+';"> <div style="position: relative;height: 180px;width: 450px"><img id="xpz_tc_logo" src="'+xpz_domain+'/assets/client/img/client_server.png" width="130" style="position: absolute;left: 20px;top: 25px;"><div style="color: #fff;font-size: 20px;position: absolute;right: 20px;top: 32px;line-height: 31px;">'+__xpz_m_popup_title1__+'<br>'+__xpz_m_popup_title2__+'</div><a style="position: absolute;bottom:30px;left: 200px;text-align:center;border:1px solid '+__xpz_kf_color__+';background:rgba(255,255,255,0.5);border-radius: 2px;width: 80px;height: 30px;line-height: 30px; display: inline-block;text-decoration: none; color: '+__xpz_kf_color__+'" href="javascript:;" onclick="dianqilai.later()">稍后再说</a><a style="background-color:#f2f2f2;position: absolute;bottom:30px;right: 60px;text-align:center;border:1px solid #f2f2f2;border-radius: 2px;width: 80px;height: 30px;line-height: 30px; display: inline-block;text-decoration: none; color: '+__xpz_kf_color__+';" href="javascript:;" onclick="dianqilai.connenct(0)">微信速聊</a></div></div>';

            }
        }
        var ddd =document.getElementById('wolive-boxxx');
        if(!ddd){
            var div =document.createElement('div');
            div.id ="dianqilai-message";
            div.className +="dianqilai-message-form";
            document.body.appendChild(div);
            var www =document.getElementById('dianqilai-message');
            if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
                www.innerHTML = '';
            } else {
                www.innerHTML='<div id="words_message" style="z-index:8888;width: 250px;border:1px solid #b3b3b3; box-shadow: 0 5px 15px rgba(0,0,0,0.5);border-radius: 5px;text-align: left;overflow: hidden;position: fixed;background: #e8e8e8;left: 1%;bottom: 1%;display:'+__xpz_message_display__+';"><div style="line-height:30px;font-size: 16px;color:#fff;padding-left:10px;background:  '+__xpz_kf_color__+'; background-repeat:no-repeat;position:relative;">'+__xpz_message_title__+'</div><div style="margin:10px;"><input id="xpz_message_name" name="xpz_message_name" style="height: 35px; font-size: 14px; width:100%;margin: 10px 0;border:1px solid #d6d6d6; border-radius: 5px;outline:none;line-height: 35px;padding-left:10px;box-sizing:border-box;" type="text" maxlength="10" placeholder="您的称呼"><input id="xpz_message_tel" name="xpz_message_tel" style="height: 35px; font-size: 14px; width:100%;margin: 10px 0;border:1px solid #d6d6d6; border-radius: 5px;outline:none;line-height: 35px;padding-left:10px;box-sizing:border-box;" type="text" maxlength="11" placeholder="您的手机号"><textarea id="xpz_message_content" style="height: 140px; font-size: 14px; width:100%;margin: 10px 0;border:1px solid #d6d6d6; border-radius: 5px;outline:none;padding-left:10px;padding-top:5px;box-sizing:border-box;" type="text" maxlength="60" placeholder="请简单描述一下您的需求，我们会第一时间给您回复。"></textarea></div><div style="border:1px solid #efefef;text-align: center; padding: 10px;font-size: 14px;background: #ffffff;"><a style="background:#efefef;border-radius: 4px;width: 80px;height: 35px;line-height: 35px; display: inline-block;text-decoration: none; color: #808080;" href="javascript:;" onclick="dianqilai.close_message()">关闭</a><a id="message_save" style="background:'+__xpz_kf_color__+';border-radius: 4px;width: 80px;height: 35px;line-height: 35px; display: inline-block;text-decoration: none; color: #ffffff;margin-left:12px;" href="javascript:;" onclick="dianqilai.submit_message();">提交</a></div></div><form id="xpz_message_form" target="xpz_message_iframe" action="'+xpz_domain+'/xpz_submit_message" method="post" style="display:none;"><input id="xpz_message_token_if" name="xpz_message_token_if"/><input type="text" name="xpz_message_name_if" id="xpz_message_name_if" /><input type="text" id="xpz_message_tel_if" name="xpz_message_tel_if" /><input type="text" name="xpz_message_content_if" id="xpz_message_content_if" /></form><iframe id="xpz_message_iframe" name="xpz_message_iframe" style="display:none;"></iframe>';
            }
        }




    },
    connenct:function(groupid){
        var id =groupid;
        var if_url = xpz_domain+'/visitor/'+xpz_token+'/'+__xpz_kf_color__.replace('#','')+'/'+__r_popup_title2__;

//                      var web =encodeURI('http://chat.lingyuncmy.com/layer?visiter_id='+this.visiter_id+'&visiter_name='+this.visiter_name+'&avatar='+this.avatar+'&business_id=12345&groupid='+groupid+'&product='+this.product);
        var web =encodeURI(if_url);
        var s =document.getElementById('wolive-talk');

        if(!s){

            var div = document.createElement('div');
            div.id ="wolive-talk";
            div.name=id;
            document.body.appendChild(div);
            div.innerHTML='<i class="dianqilai-close" onclick="dianqilai.narrow()"></i><iframe id="wolive-iframe" src="'+web+'"></iframe>'
        }else{

            var title =s.name;
            if(title == groupid){
                s.style ='display:block';
            }else{
                s.parentNode.removeChild(s);
                dianqilai.connenct(groupid);
            }
        }
        dianqilai.later();
        dianqilai.chongzhi();
        dianqilai.copydy();
    },
    narrow:function(){
        document.getElementById('wolive-talk').style="display:none";
    },
    later:function(){
        document.getElementById('dianqilai-zjtk').style="display:none";
        dianqilai.copydy();
    },
    chongzhi:function(){
        if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
            //聊天
            document.getElementById('wolive-talk').style = "width:60%;height:70%";

        }

    },
    copydy:function(){
        if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
            var btns = document.getElementById('xpz_container');
            var clipboard = new ClipboardJS(btns);
            clipboard.on('success', function(e) {
                //成功后执行这里
            });
            clipboard.on('error', function(e) {
                console.log(e);
            });
        }
    },
    close_message:function (){
        document.getElementById('dianqilai-message').style="display:none";
        dianqilai.copydy();
    },
    submit_message:function(){
        var xpz_message_name = document.getElementById("xpz_message_name").value;
        var xpz_message_tel = document.getElementById("xpz_message_tel").value;
        var xpz_message_content = document.getElementById("xpz_message_content").value;

//                        console.log(xpz_message_tel);
        if(xpz_message_name==""||xpz_message_name==null||xpz_message_name==undefined){
            alert("留言称呼不能为空！");
            return false;
        }
        if(!(/^1\d{10}$/.test(xpz_message_tel))){
            alert("手机号码有误，请重填");
            return false;
        }
        if(xpz_message_content==""||xpz_message_content==null||xpz_message_content==undefined){
            alert('留言内容不能为空！');
            return false;
        }
        if(xpz_message_content.length < 6){
            alert('留言内容不能少于6个字！');
            return false;
        }

        document.getElementById("xpz_message_tel_if").value = xpz_message_tel;
        document.getElementById("xpz_message_name_if").value = xpz_message_name;
        document.getElementById("xpz_message_content_if").value = xpz_message_content;
        document.getElementById("xpz_message_token_if").value = xpz_token;

        document.getElementById('xpz_message_form').submit();
        dianqilai.close_message();
    }
}

window.onload =dianqilai.open();

function close_talk(){
//            console.log('3333');
    document.getElementById('wolive-talk').style="display:none";
}



